package com.topscore.uke.mvp.presenters;

import android.app.assist.AssistStructure;
import android.content.DialogInterface;
import android.app.AlertDialog;

import com.topscore.uke.main.BaseApplication;
import com.topscore.uke.mvp.contractors.LogoutContractor;
import com.topscore.uke.utils.UserInfoManager;

/**
 * Created by 71468 on 2018/3/19.
 */

public class LogoutPresenter implements LogoutContractor, LogoutContractor.Presenter {
    private View mView;

    private AlertDialog mAlertDialog;

    public LogoutPresenter(View view) {
        this.mView = view;
        mAlertDialog = new AlertDialog.Builder(mView.getContext())
                .setTitle("提示")
                .setMessage("您确定要退出登录吗？" + "\n" + "您的用户信息将被安全删除")
                .setNegativeButton("取消", (dialogInterface, i) ->
                        mAlertDialog.dismiss()
                )
                .setPositiveButton("退出",(dialogInterface, i) -> clearUserInfo())
                .create();
    }

    @Override
    public void logout() {
        mAlertDialog.show();
    }

    private void clearUserInfo() {
        UserInfoManager.updateUserInfo(null);

        mView.onLogoutSuccess();
    }
}
